TARGET = usbvp1022air
OBJS = usbvp1022air.o
MDIR = drivers/misc/

EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
#CURRENT = 2.6.18-ck1-pld
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)

.PHONY: load remote rm rebuild

obj-m      := $(TARGET).o

default:
	make -C $(KDIR) M="$(PWD)" modules

$(TARGET).o: 
	$(LD) $(LDFLAGS) -r -o $@ $(OBJS)

rm:	
	@rmmod $(TARGET)

load:
	@modprobe $(TARGET) 

rebuild: default install load rm load
	
.PHONY: remote
remote:
	@gcc remote_test/remote.c -o remote_test/remote
	@ln -s -f remote_test/remote remote
	@./remote
		
ifneq (,$(findstring 2.4.,$(CURRENT)))
install:
	su -c "mkdir -p $(DEST) && cp -v $(TARGET).o $(DEST) && /sbin/depmod -a"
else
install:
	su -c "mkdir -p $(DEST) && cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
endif

clean:
	-rm -f *.o *.ko .*.cmd .*.flags *.mod.c *~

-include $(KDIR)/Rules.make
